//
//  PickerBoot.swift
//  SwiftUIWidgetDemo
//
//  Created by alanzhangg on 2023/7/17.
//

import SwiftUI

enum Flavor: String, CaseIterable, Identifiable {
    case chocolate, vanilla, strawberry
    var id: Self {self}
}

enum Topping: String, CaseIterable, Identifiable {
    case nuts, cookies, blueberries
    var id: Self {self}
}

extension Flavor{
    var suggestedTopping: Topping {
        switch self {
        case .chocolate: return .nuts
        case .vanilla: return .cookies
        case .strawberry: return .blueberries
        }
        
    }
}

struct PickerBoot: View {
    
    @State private var selectedFlavor: Flavor = .chocolate
    @State private var suggestedTopping: Topping = .nuts
    
    init() {
        UISegmentedControl.appearance().selectedSegmentTintColor = .red
    }
    
    var body: some View {
        List{
            Picker("Flavor", selection: $suggestedTopping) {
                ForEach(Flavor.allCases) { flavor in
                    Text(flavor.rawValue.capitalized)
                        .tag(flavor.suggestedTopping)
                }
            }
            HStack{
                Text("Suggested Topping")
                Spacer()
                Text(suggestedTopping.rawValue.capitalized)
                    .foregroundStyle(.secondary)
            }
        }
        .pickerStyle(.segmented)

    }
}

#Preview {
    PickerBoot()
}
